package com.jwcao.common.cast.benchmark;

import cn.hutool.json.JSONUtil;
import com.jwcao.common.cast.Cast;
import com.jwcao.common.cast.TestRunner;
import java.io.IOException;
import java.util.Date;
import javax.xml.crypto.Data;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
 * name: Benchmark description: TODO
 *
 * @author caojingwei date: 2023/3/25 18:49
 */
@Slf4j
public class Benchmark {

    @BeforeAll
    public static void run() throws IOException, ClassNotFoundException {
        TestRunner.run();
    }

    static A a = A.builder()
        .id("id")
        .name("A")
        .value("value")
        .build();

    @Test
    public void test() {

        long start2 = (new Date()).getTime();

        for (int i = 0; i < 500000; i++) {
            Cast.get(a, B.class);
        }
        long end2 = (new Date()).getTime();
        log.info(end2 - start2 + "");


        long start = (new Date()).getTime();
        for (int i = 0; i < 500000; i++) {
            a.toB();
        }
        long end = (new Date()).getTime();
        log.info(end - start + "");


        long start3 = (new Date()).getTime();
        for (int i = 0; i < 500000; i++) {
            JSONUtil.toBean(JSONUtil.toJsonStr(a), B.class);
        }
        long end3 = (new Date()).getTime();
        log.info(end3 - start3 + "");
    }

}
